package com.yegs.admin.generator.controller;

import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.yegs.admin.generator.entity.Table;
import com.yegs.admin.generator.service.impl.GeneratorServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/generator")
public class GeneratorController {

    @Autowired
    private GeneratorServiceImpl generatorService;

    @RequestMapping("/getTables")
    public List<String> getTables(){
        List<String>  list = generatorService.getDatabases();
        System.out.println(list.size());
        return list;
    };
    public void genneartor(){
        String dirPath =System.getProperty("user.dir")+"\\com\\yegs\\admin\\business";
        AutoGenerator ag = new AutoGenerator();
        // 全局配置
        GlobalConfig gc = new GlobalConfig();
        gc.setOutputDir(dirPath);
        gc.setAuthor("lqh");
        gc.setFileOverride(true); //是否覆盖
        gc.setActiveRecord(true);// 不需要ActiveRecord特性的请改为false
        gc.setEnableCache(false);// XML 二级缓存
        gc.setBaseResultMap(true);// XML ResultMap
        gc.setBaseColumnList(true);// XML columList

        // 策略配置
        StrategyConfig strategy = new StrategyConfig();
        ag.setStrategy(strategy);


        // 包配置
        PackageConfig pc = new PackageConfig();
        pc.setParent("com");
        pc.setModuleName("warrior");
        pc.setController("controler");
        pc.setEntity("entity");
        pc.setMapper("mapper");
        pc.setService("service");
        pc.setServiceImpl("serviceImpl");
        pc.setXml("mapperXml");

        ag.setPackageInfo(pc);

    }

}
